package com.example.testapp.activity.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by l on 2016/10/11.
 * 字符验证工具
 */

public class CharCheckUtil {

    /**
     * 判断是否是数字
     *
     * @param str
     * @return
     */
    public static boolean isAllDigit(String str) {
        if (!str.equals("") && str.length() > 0){
            int len = 0;
            for(int idx = 0; idx < str.length(); idx++){
                if (Character.isDigit(str.charAt(idx))){
                    len++;
                }
            }
            if (len == str.length()){
                return true;
            }
        }
        return false;
    }

    /**
     * 手机号码验证
     *
     * @param phonenum
     * @return
     */
    public static boolean isPhoneNum(String phonenum) {
        Pattern pattern = Pattern.compile("^(1[0-9])\\d{9}$");
        Matcher m = pattern.matcher(phonenum);
        if (m.matches()){
            return true;
        }else {
            return false;
        }
    }
}
